package com.zmn.oms.admin.controller.comment;

import com.zmn.base.common.data.common.constant.TagConsts;
import com.zmn.common.constant.GlobalConsts;
import com.zmn.oms.admin.controller.OmsBaseController;
import com.zmn.oms.business.interfaces.comment.OrderCommentBService;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.common.vo.KVDict;
import com.zmn.oms.model.dto.comment.ZsCommentRemarkDTO;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.oms.model.vo.work.modify.must.ZsReplyVisitVO;
import com.zmn.oms.services.interfaces.work.OrderWorkService;
import com.zmn.oms.zmn.business.interfaces.comment.ZsOrderCommentBService;
import com.zmn.oms.zmn.business.interfaces.work.ZsOrderWorkOperatePermissionBService;
import com.zmn.oms.zmn.normal.business.interfaces.work.customwork.ZsNormalCustomWorkBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 类描述：操作订单评价
 *
 * @author yangjiangming
 * @date 2018/11/26 9:30
 */

@Controller
@RequestMapping("/order_comment/modify")
public class CommentModifyController extends OmsBaseController {

    @Autowired
    ZsOrderCommentBService zsOrderCommentBService;
    @Autowired
    OrderWorkService orderWorkService;
    @Autowired
    ZsNormalCustomWorkBService zsNormalCustomWorkBService;
    @Autowired
    ZsOrderWorkOperatePermissionBService orderWorkOperatePermissionBService;
    @Autowired
    OrderCommentBService orderCommentBService;

    /**
     * 工单操作页面-详情
     */
    @RequestMapping(value = "/detail")
    public ModelAndView modifyDetail(Long orderId, Long workId) {
        ModelAndView mv = new ModelAndView("comment/modify/detail");
        return mv;
    }

    /**
     * 备注
     */
    @RequestMapping(value = "/remark")
    public ModelAndView remark(Long orderId, Long workId, Long operateId) {
        ModelAndView mv = new ModelAndView("comment/modify/remark");

        // code map
        OrderWork orderWork = orderWorkService.findOrderWorkByKey(orderId, workId);
        List<KVDict<Integer>> codeMapList = baseCodeService.getBaseCodeMap(GlobalConsts.PLAT_MARK_ZMN, TagConsts.TAG_ONE_TYPE_OMS_COMMENT_REMRK);

        mv.addObject("codeMapList", codeMapList);
        mv.addObject("orderWork", orderWork);
        return mv;
    }

    /**
     * 保存评价备注
     */
    @RequestMapping(value = "/save/remark")
    @ResponseBody
    public ResultDTO saveRemark(@RequestBody ZsCommentRemarkDTO commentRemarkDTO) throws Exception {
        zsOrderCommentBService.saveRemark(commentRemarkDTO);
        return ResultDTO.success();
    }

    /**
     * 回访
     */
    @RequestMapping(value = "/reply/visit")
    public ModelAndView replyVisit(Long orderId, Long workId, Long operateId) {
        ModelAndView mv = new ModelAndView("comment/modify/replyvisit");
        ZsReplyVisitVO replyVisitVO = zsNormalCustomWorkBService.findReplyVisit(orderId, workId);

        // code map
        List<KVDict<Integer>> replyVisitCodeMapList = baseCodeService.getBaseCodeMap(GlobalConsts.PLAT_MARK_ZMN, TagConsts.TAG_ONE_TYPE_OMS_REPLY_VISIT_TYPE);
        replyVisitVO.setReplyVisitCodeMapList(replyVisitCodeMapList);

        mv.addObject("replyVisitVO", replyVisitVO);
        mv.addObject("operateId", operateId);
        return mv;
    }
}
